{% extends "base_project.html" %}
{% load compress humanize static hc_extras %}

{% block title %}
{% if is_new %}
Add Signal Integration - {% site_name %}
{% else %}
Signal Settings - {% site_name %}
{% endif %}
{% endblock %}


{% block content %}
<div class="row">
<div class="col-sm-12">
    <h1>Signal</h1>

    <p>Get a Signal message when a check goes up or down.</p>

    <h2>Integration Settings</h2>

    <form method="post" class="form-horizontal">
        {% csrf_token %}
        <div class="form-group {{ form.label.css_classes }}">
            <label for="id_label" class="col-sm-2 control-label">Label</label>
            <div class="col-sm-6">
                <input
                    id="id_label"
                    type="text"
                    class="form-control"
                    name="label"
                    placeholder="Alice's Phone"
                    value="{{ form.label.value|default:"" }}">

                {% if form.label.errors %}
                <div class="help-block">
                    {{ form.label.errors|join:"" }}
                </div>
                {% else %}
                <span class="help-block">
                    Optional. If you add multiple phone numbers,
                    the labels will help you tell them apart.
                </span>
                {% endif %}
            </div>
        </div>

        <div class="form-group {{ form.phone.css_classes }}">
            <label for="id_number" class="col-sm-2 control-label">Phone Number</label>
            <div class="col-sm-6">
                <div class="input-group">
                    <input
                        id="id_number"
                        type="tel"
                        class="form-control"
                        name="phone"
                        placeholder="+1234567890"
                        value="{{ form.phone.value|default:"" }}">

                    <span class="input-group-btn">
                        <button
                            id="signal-verify-btn"
                            type="button"
                            class="btn btn-default"
                            data-verify-url="{% url 'hc-signal-verify' %}">
                            <span>Send Test Message!</span>
                            <div class="spinner"></div>
                        </button>
                    </span>
                </div>

                {% if form.phone.errors %}
                <div class="help-block">
                    {{ form.phone.errors|join:"" }}
                </div>
                {% else %}
                <span class="help-block">
                    Make sure the phone number starts with "+" and  has the
                    country code.
                </span>
                {% endif %}

                <div id="verify-result"></div>
            </div>
        </div>

        <div class="form-group {{ form.down.css_classes }}">
            <label class="col-sm-2 control-label">Notify When</label>
            <div class="col-sm-10">
                <label class="checkbox-container">
                    <input
                        type="checkbox"
                        name="down"
                        value="true"
                        {% if form.down.value %} checked {% endif %}>
                    <span class="checkmark"></span>
                    A check goes <strong>down</strong>
                </label>
                <label class="checkbox-container">
                    <input
                        type="checkbox"
                        name="up"
                        value="true"
                        {% if form.up.value %} checked {% endif %}>
                    <span class="checkmark"></span>
                    A check goes <strong>up</strong>
                    {% if form.down.errors %}
                    <div class="help-block">
                        {{ form.down.errors|join:"" }}
                    </div>
                    {% endif %}
                </label>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button
                    id="submit-btn"
                    type="submit"
                    class="btn btn-primary"
                    title="Please verify the number by sending a test message first."
                    disabled>Save Integration</button>
            </div>
        </div>
    </form>
</div>
</div>
{% endblock %}

{% block scripts %}
    {{ block.super }}
    {% compress js %}
    <script src="{% static 'js/signal_form.js' %}"></script>
    {% endcompress %}
{% endblock %}
